package com.spotalog.server.service.search;

import javax.inject.Inject;
import javax.inject.Provider;

import com.google.appengine.api.search.Document;
import com.google.appengine.api.search.Field;
import com.google.common.base.Joiner;

class DocumentConverter {
	private Provider<Document.Builder> documents;
	private Provider<Field.Builder> fields;
	private Joiner joiner;
	private final Class<?> clazz;

	DocumentConverter(Class<?> clazz) {
		this.clazz = clazz;
	}

	@Inject
	void setDocumentBuilder(Provider<Document.Builder> documents) {
		this.documents = documents;
	}

	@Inject
	void setFieldBuilder(Provider<Field.Builder> fields) {
		this.fields = fields;
	}

	@Inject
	void setJoiner(Joiner joiner) {
		this.joiner = joiner;
	}

	Field.Builder field(String name) {
		return this.fields.get().setName(name);
	}

	Document.Builder document(Object id) {
		return this.documents.get().setId(this.joiner.join(this.clazz.getName(), id));
	}
}
